Code
# load libraries
library(tidyverse)
library(here)
library(janitor)
library(patchwork)
library(tsibble)
library(feasts)
library(fable)
library(dplyr)Task 2: Willamette Falls Fish Passage Time Series Summary
This report includes population data on Coho, Jack Coho, and Steelhead fish collected daily at the Willamette Falls fish ladder between 2001-2010. The plots below illustrate both the seasonality of fish species migrating through Willamette Falls and the general trend in population size over the ten year period. Also included is a forecasting model used to predict Coho Salmon population from 2010-2025.
U.S. Army Corps of Engineers, NWD and Chelan, Douglas and Grant County PUDs, Yakima Klickitat Fisheries Project, Colville Tribes Fish & Wildlife (OBMEP), Oregon Department of Fish & Wildlife, Washington Department of Fish & Wildlife. 2010. Columbia River DART Adult Passage Counts Graphic & Text. WFF-Willamette Falls [2001]. Columbia Basin Research. University of Washington School of Aquatic and Fishery Sciences. https://www.cbr.washington.edu/dart/query/adult_graph_text
# load libraries
library(tidyverse)
library(here)
library(janitor)
library(patchwork)
library(tsibble)
library(feasts)
library(fable)
library(dplyr)# load and clean data
fish_data <- read_csv(here('data', 'willamette_fish_passage.csv'))
fish_df <- fish_data %>%
clean_names() %>%
mutate(date = lubridate:: mdy(date)) %>%
select(date, coho, jack_coho, steelhead) %>%
replace_na(list(coho=0, jack_coho=0, steelhead=0))# convert to time series
fish_ts <- fish_df %>%
as_tsibble(key = NULL,
index = date)# plot time series for each species
coho <- ggplot(fish_ts, aes(x = date)) +
geom_line(aes(y = coho)) +
theme_minimal() +
labs(x = " ",
y = "Coho")
jack <- ggplot(fish_ts, aes(x = date)) +
geom_line(aes(y = jack_coho)) +
theme_minimal() +
labs(x = " ",
y = "Jack Coho")
steel <- ggplot(fish_ts, aes(x = date)) +
geom_line(aes(y=steelhead)) +
theme_minimal() +
labs(x = "Year",
y = "Steelhead")
fish_graph <- coho / jack / steel +
plot_annotation(title = "Fish Observed at the Willamette Falls Fish Ladder from 2001-2010" ,
caption = "The x axis represents time in years between 2001-2010. Note the difference in magnitude of the y axes; the top
graph showing population is measured for Coho salmon by intervals of 500, the middle graph showing population
trends for Jack Coho salmon increases by intervals of 50, and the bottom graph showing population trends for
Steelhead increases by intervals of 100.",
theme = theme(plot.title = element_text(size = 14, hjust = 0.5),
plot.caption = element_text(hjust = 0.5)))
fish_graph# make individual time series for each fish species
coho_ts <- fish_df %>%
pivot_longer("coho":"steelhead",
names_to = "species",
values_to = "count") %>%
filter(species == "coho") %>%
as_tsibble(key = NULL,
index = date)
jack_ts <- fish_df %>%
pivot_longer("coho":"steelhead",
names_to = "species",
values_to = "count") %>%
filter(species == "jack_coho") %>%
as_tsibble(key = NULL,
index = date)
steel_ts <- fish_df %>%
pivot_longer("coho":"steelhead",
names_to = "species",
values_to = "count") %>%
filter(species == "steelhead") %>%
as_tsibble(key = NULL,
index = date)
# create season plots
coho_season <- coho_ts %>%
gg_season(y = count,
pal = rainbow(n=9)) +
theme_light() +
labs(x = " ",
y = "Coho") +
theme(legend.position = "none")
jack_season <- jack_ts %>%
gg_season(y = count,
pal = rainbow(n=9)) +
theme_light() +
labs(x = " ",
y = "Jack Coho")
steel_season <- steel_ts %>%
gg_season(y = count,
pal = rainbow(n=9)) +
theme_light() +
labs(x = "Year",
y = "Steelhead") +
theme(legend.position = "none")
fish_season <- coho_season / jack_season / steel_season +
plot_annotation(caption = "The plots above show the annual trends of fish species: coho (top), jack coho (center), and steelhead (bottom)
at the Willamette Falls fish ladder from 2001-2010. The x axis shows time in months and the y axes show counts of
individuals of each species. Note the different y-axes scales; Coho population is shown in intervals of 250,
Jack Coho in intervals of 50, and Steelhead 100. The colors represent each year between 2001-2010 with red representing
2001 followed by a rainbow gradient where purple and pink represent the most recent years. " ,
theme = theme(plot.caption = element_text(hjust = 0.5)))
fish_seasonfish_totals <- fish_ts %>%
separate(date, c('year', 'month', 'day')) %>%
group_by(year) %>%
summarise(Coho = sum(coho),
Jack_Coho = sum(jack_coho),
Steelhead = sum(steelhead)) %>%
pivot_longer("Coho":"Steelhead",
names_to = "species",
values_to = "total")
fish_total_plot <- ggplot(data = fish_totals,
aes(x = year,
y = total,
fill = species)) +
geom_col() +
facet_wrap(~species, ncol=1, scales = "free") +
labs(x = "Year",
y = "Total Fish at Fish Ladder",
fill = "Fish Species",
caption = "The figures above show the annual totals for fish passage at the Willamette fish lader from 2001-2010.
The top graph (red) represents coho salmon, the center graph (green) represents jack coho salmon, and the
bottom graph (blue) represents steelhead. The x axis shows time in years, and the y axes represent number
of individuals for each species. Note the different y-axes scales for the different species; Coho population
is shown in intervals of 2500, Jack Coho in intervals of 500, and Steelhead 5000") +
theme(plot.caption = element_text(hjust = 0.5))
plot(fish_total_plot)# create model
coho_month_df <- fish_df %>%
separate(date, c('year', 'month', 'day')) %>%
mutate(yearmonth = paste(year, month, sep = "-"),
date = yearmonth(yearmonth)) %>%
select(date, coho) %>%
group_by(date) %>%
summarise(count = sum(coho))
coho_month_ts <- coho_month_df %>%
as_tsibble(key = NULL,
index = date)
coho_fit <- coho_month_ts %>%
model(ets = ETS(count ~ season(method = "A") + trend(method = "A")))
coho_forecast <- coho_fit %>%
forecast(h = "15 years")
coho_forecast %>%
autoplot(coho_month_ts)